package controllers

import (
	"bluebell/logic"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"strconv"
)

//查询到所有的社区
func CommunityHandler(c *gin.Context) {
	//1. 查询到所有的社区(id,name)
	data, err := logic.GetCommunityList()
	if err != nil {
		zap.L().Error("logic.CommunityList with failed")
		ResponseError(c, CodeServerBusy)
	}
	ResponseSuccess(c, data)

}

// 社区分类详情
func CommunityDetailHandler(c *gin.Context) {
	//1. 获取社区id
	idStr := c.Param("id")
	id, err := strconv.ParseInt(idStr, 10, 64) //将id转成10进制
	if err != nil {
		ResponseError(c, CodeInvalidParam)
		return
	}
	data, err := logic.GetCommunityDetail(id)
	if err != nil {
		zap.L().Error("logic.CommunityList with failed", zap.Error(err))
		ResponseError(c, CodeServerBusy)
		return
	}
	ResponseSuccess(c, data)

}
